# Copyright (C) 2012-2021  The Bochs Project
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA

# Makefile for the iodev/sound component of bochs


.SUFFIXES: .cc

prefix          = /usr/local
exec_prefix     = ${prefix}
srcdir          = .

bindir          = ${exec_prefix}/bin
libdir          = ${exec_prefix}/lib
datarootdir     = ${prefix}/share
mandir          = ${datarootdir}/man
man1dir         = $(mandir)/man1
man5dir         = $(mandir)/man5
docdir          = $(datarootdir)/doc/bochs
sharedir        = $(datarootdir)/bochs
top_builddir    = ..
top_srcdir      = ../..

SHELL = /bin/sh



CXX = g++
CXXFLAGS = $(BX_INCDIRS) -g -O2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES   -I/usr/include/SDL2 -D_REENTRANT

LDFLAGS = 
LIBS = 
RANLIB = ranlib
PLUGIN_PATH=${exec_prefix}/lib
top_builddir    = ../..
LIBTOOL=$(SHELL) $(top_builddir)/libtool
WIN32_DLL_IMPORT_LIBRARY=../../

SOUNDLOW_OBJS = sounddummy.o soundfile.o 

BX_INCDIRS = -I.. -I../.. -I$(srcdir)/.. -I$(srcdir)/../.. -I../../instrument/stubs -I$(srcdir)/../../instrument/stubs
LOCAL_CXXFLAGS = $(MCH_CFLAGS)

OBJS_THAT_CANNOT_BE_PLUGINS = \
  soundmod.o \
  soundlow.o

OBJS_THAT_CAN_BE_PLUGINS = \
   \
  $(SOUNDLOW_OBJS)

OBJS_THAT_SUPPORT_OTHER_PLUGINS = opl.o

NONPLUGIN_OBJS = $(OBJS_THAT_CANNOT_BE_PLUGINS) $(OBJS_THAT_CAN_BE_PLUGINS) $(OBJS_THAT_SUPPORT_OTHER_PLUGINS)
PLUGIN_OBJS = 
ALSA_SOUND_LINK_OPTS = 
SDL_SOUND_LINK_OPTS = 
WIN_SOUND_LINK_OPTS = -lwinmm
WIN_SOUND_LINK_OPTS_VCPP = winmm.lib

SOUNDHW_DLL_TARGETS = 

all: libsound.a

plugins: 

plugins_gcc: $(PLUGIN_OBJS:%.o=libbx_%.la)

plugins_msvc: bx_sounddummy.dll bx_soundfile.dll bx_soundwin.dll $(SOUNDHW_DLL_TARGETS)

libsound.a: $(NONPLUGIN_OBJS)
	rm -f  libsound.a
	ar rv $@ $(NONPLUGIN_OBJS)
	$(RANLIB) libsound.a

# standard compile rule for C++ files
.cc.o:
	$(CXX) -c  $(CXXFLAGS) $(LOCAL_CXXFLAGS) $< -o $@

##### building plugins with libtool
%.lo: %.cc
	$(LIBTOOL) --mode=compile --tag CXX $(CXX) -c $(CXXFLAGS) $(LOCAL_CXXFLAGS) $< -o $@

libbx_%.la: %.lo
	$(LIBTOOL) --mode=link --tag CXX $(CXX) -module $< -o $@ -rpath $(PLUGIN_PATH)

# special link rules for plugins that require more than one object file
libbx_sb16.la: sb16.lo opl.lo
	$(LIBTOOL) --mode=link --tag CXX $(CXX) -module sb16.lo opl.lo -o libbx_sb16.la -rpath $(PLUGIN_PATH)

libbx_soundalsa.la: soundalsa.lo
	$(LIBTOOL) --mode=link --tag CXX $(CXX) -module soundalsa.lo -o libbx_soundalsa.la -rpath $(PLUGIN_PATH) $(ALSA_SOUND_LINK_OPTS)

libbx_soundsdl.la: soundsdl.lo
	$(LIBTOOL) --mode=link --tag CXX $(CXX) -module soundsdl.lo -o libbx_soundsdl.la -rpath $(PLUGIN_PATH) $(SDL_SOUND_LINK_OPTS)

#### building DLLs for win32 (Cygwin and MinGW/MSYS)
bx_%.dll: %.o
	$(CXX) $(CXXFLAGS) -shared -o $@ $< $(WIN32_DLL_IMPORT_LIBRARY)

# special link rules for plugins with Cygwin, MinGW/MSYS and MSVC nmake
bx_sb16.dll: sb16.o opl.o
	 sb16.o opl.o $(WIN32_DLL_IMPORT_LIBRARY)

bx_es1370.dll: es1370.o
	 es1370.o $(WIN32_DLL_IMPORT_LIBRARY)

bx_sounddummy.dll: sounddummy.o
	 sounddummy.o $(WIN32_DLL_IMPORT_LIBRARY)

bx_soundfile.dll: soundfile.o
	 soundfile.o $(WIN32_DLL_IMPORT_LIBRARY)

bx_soundwin.dll: soundwin.o
	 soundwin.o $(WIN32_DLL_IMPORT_LIBRARY) $(WIN_SOUND_LINK_OPTS)

##### end DLL section

clean:
	rm -f  -rf .libs *.lo *.o *.la *.a *.dll *.exp *.lib

dist-clean: clean
	rm -f  Makefile

###########################################
# dependencies generated by
#  gcc -MM -I.. -I../.. -I../../instrument/stubs *.cc | sed -e 's/\.cc/.cc/g'
#  gcc -MM -I.. -I../.. -I../../instrument/stubs *.cc | \
#     sed -e 's/\.cc/.cc/g' -e 's/\.o:/.lo:/g'
#
# This means that every source file is listed twice, once with a .o rule
# and then again with an identical .lo rule.  The .lo rules are used when
# building plugins.
###########################################
es1370.o: es1370.cc ../iodev.h ../../bochs.h ../../config.h ../../osdep.h \
 ../../gui/paramtree.h ../../logio.h ../../instrument/stubs/instrument.h \
 ../../misc/bswap.h ../../plugin.h ../../extplugin.h ../../param_names.h \
 ../../pc_system.h ../../bx_debug/debug.h ../../config.h ../../osdep.h \
 ../../memory/memory-bochs.h ../../gui/siminterface.h ../../gui/gui.h \
 soundlow.h ../../bxthread.h soundmod.h ../pci.h es1370.h
opl.o: opl.cc ../iodev.h ../../bochs.h ../../config.h ../../osdep.h \
 ../../gui/paramtree.h ../../logio.h ../../instrument/stubs/instrument.h \
 ../../misc/bswap.h ../../plugin.h ../../extplugin.h ../../param_names.h \
 ../../pc_system.h ../../bx_debug/debug.h ../../config.h ../../osdep.h \
 ../../memory/memory-bochs.h ../../gui/siminterface.h ../../gui/gui.h \
 opl.h
sb16.o: sb16.cc ../iodev.h ../../bochs.h ../../config.h ../../osdep.h \
 ../../gui/paramtree.h ../../logio.h ../../instrument/stubs/instrument.h \
 ../../misc/bswap.h ../../plugin.h ../../extplugin.h ../../param_names.h \
 ../../pc_system.h ../../bx_debug/debug.h ../../config.h ../../osdep.h \
 ../../memory/memory-bochs.h ../../gui/siminterface.h ../../gui/gui.h \
 soundlow.h ../../bxthread.h soundmod.h sb16.h opl.h
soundalsa.o: soundalsa.cc ../../bochs.h ../../config.h ../../osdep.h \
 ../../gui/paramtree.h ../../logio.h ../../instrument/stubs/instrument.h \
 ../../misc/bswap.h ../../plugin.h ../../extplugin.h ../../pc_system.h \
 soundlow.h ../../bxthread.h soundmod.h soundalsa.h
sounddummy.o: sounddummy.cc ../../bochs.h ../../config.h ../../osdep.h \
 ../../gui/paramtree.h ../../logio.h ../../instrument/stubs/instrument.h \
 ../../misc/bswap.h ../../plugin.h ../../extplugin.h soundlow.h \
 ../../bxthread.h
soundfile.o: soundfile.cc ../../bochs.h ../../config.h ../../osdep.h \
 ../../gui/paramtree.h ../../logio.h ../../instrument/stubs/instrument.h \
 ../../misc/bswap.h ../../plugin.h ../../extplugin.h soundlow.h \
 ../../bxthread.h soundmod.h soundfile.h
soundlow.o: soundlow.cc ../../bochs.h ../../config.h ../../osdep.h \
 ../../gui/paramtree.h ../../logio.h ../../instrument/stubs/instrument.h \
 ../../misc/bswap.h ../../plugin.h ../../extplugin.h ../../pc_system.h \
 soundlow.h ../../bxthread.h
soundmod.o: soundmod.cc ../../bochs.h ../../config.h ../../osdep.h \
 ../../gui/paramtree.h ../../logio.h ../../instrument/stubs/instrument.h \
 ../../misc/bswap.h ../../plugin.h ../../extplugin.h \
 ../../gui/siminterface.h ../../param_names.h soundmod.h soundlow.h \
 ../../bxthread.h
soundoss.o: soundoss.cc ../../bochs.h ../../config.h ../../osdep.h \
 ../../gui/paramtree.h ../../logio.h ../../instrument/stubs/instrument.h \
 ../../misc/bswap.h ../../plugin.h ../../extplugin.h ../../pc_system.h \
 soundlow.h ../../bxthread.h soundmod.h soundoss.h
soundosx.o: soundosx.cc ../../bochs.h ../../config.h ../../osdep.h \
 ../../gui/paramtree.h ../../logio.h ../../instrument/stubs/instrument.h \
 ../../misc/bswap.h ../../plugin.h ../../extplugin.h soundlow.h \
 ../../bxthread.h soundmod.h soundosx.h
soundsdl.o: soundsdl.cc ../../bochs.h ../../config.h ../../osdep.h \
 ../../gui/paramtree.h ../../logio.h ../../instrument/stubs/instrument.h \
 ../../misc/bswap.h ../../plugin.h ../../extplugin.h ../../pc_system.h \
 soundlow.h ../../bxthread.h soundmod.h soundsdl.h
soundwin.o: soundwin.cc ../../bochs.h ../../config.h ../../osdep.h \
 ../../gui/paramtree.h ../../logio.h ../../instrument/stubs/instrument.h \
 ../../misc/bswap.h ../../plugin.h ../../extplugin.h ../../pc_system.h \
 soundlow.h ../../bxthread.h soundmod.h soundwin.h
es1370.lo: es1370.cc ../iodev.h ../../bochs.h ../../config.h ../../osdep.h \
 ../../gui/paramtree.h ../../logio.h ../../instrument/stubs/instrument.h \
 ../../misc/bswap.h ../../plugin.h ../../extplugin.h ../../param_names.h \
 ../../pc_system.h ../../bx_debug/debug.h ../../config.h ../../osdep.h \
 ../../memory/memory-bochs.h ../../gui/siminterface.h ../../gui/gui.h \
 soundlow.h ../../bxthread.h soundmod.h ../pci.h es1370.h
opl.lo: opl.cc ../iodev.h ../../bochs.h ../../config.h ../../osdep.h \
 ../../gui/paramtree.h ../../logio.h ../../instrument/stubs/instrument.h \
 ../../misc/bswap.h ../../plugin.h ../../extplugin.h ../../param_names.h \
 ../../pc_system.h ../../bx_debug/debug.h ../../config.h ../../osdep.h \
 ../../memory/memory-bochs.h ../../gui/siminterface.h ../../gui/gui.h \
 opl.h
sb16.lo: sb16.cc ../iodev.h ../../bochs.h ../../config.h ../../osdep.h \
 ../../gui/paramtree.h ../../logio.h ../../instrument/stubs/instrument.h \
 ../../misc/bswap.h ../../plugin.h ../../extplugin.h ../../param_names.h \
 ../../pc_system.h ../../bx_debug/debug.h ../../config.h ../../osdep.h \
 ../../memory/memory-bochs.h ../../gui/siminterface.h ../../gui/gui.h \
 soundlow.h ../../bxthread.h soundmod.h sb16.h opl.h
soundalsa.lo: soundalsa.cc ../../bochs.h ../../config.h ../../osdep.h \
 ../../gui/paramtree.h ../../logio.h ../../instrument/stubs/instrument.h \
 ../../misc/bswap.h ../../plugin.h ../../extplugin.h ../../pc_system.h \
 soundlow.h ../../bxthread.h soundmod.h soundalsa.h
sounddummy.lo: sounddummy.cc ../../bochs.h ../../config.h ../../osdep.h \
 ../../gui/paramtree.h ../../logio.h ../../instrument/stubs/instrument.h \
 ../../misc/bswap.h ../../plugin.h ../../extplugin.h soundlow.h \
 ../../bxthread.h
soundfile.lo: soundfile.cc ../../bochs.h ../../config.h ../../osdep.h \
 ../../gui/paramtree.h ../../logio.h ../../instrument/stubs/instrument.h \
 ../../misc/bswap.h ../../plugin.h ../../extplugin.h soundlow.h \
 ../../bxthread.h soundmod.h soundfile.h
soundlow.lo: soundlow.cc ../../bochs.h ../../config.h ../../osdep.h \
 ../../gui/paramtree.h ../../logio.h ../../instrument/stubs/instrument.h \
 ../../misc/bswap.h ../../plugin.h ../../extplugin.h ../../pc_system.h \
 soundlow.h ../../bxthread.h
soundmod.lo: soundmod.cc ../../bochs.h ../../config.h ../../osdep.h \
 ../../gui/paramtree.h ../../logio.h ../../instrument/stubs/instrument.h \
 ../../misc/bswap.h ../../plugin.h ../../extplugin.h \
 ../../gui/siminterface.h ../../param_names.h soundmod.h soundlow.h \
 ../../bxthread.h
soundoss.lo: soundoss.cc ../../bochs.h ../../config.h ../../osdep.h \
 ../../gui/paramtree.h ../../logio.h ../../instrument/stubs/instrument.h \
 ../../misc/bswap.h ../../plugin.h ../../extplugin.h ../../pc_system.h \
 soundlow.h ../../bxthread.h soundmod.h soundoss.h
soundosx.lo: soundosx.cc ../../bochs.h ../../config.h ../../osdep.h \
 ../../gui/paramtree.h ../../logio.h ../../instrument/stubs/instrument.h \
 ../../misc/bswap.h ../../plugin.h ../../extplugin.h soundlow.h \
 ../../bxthread.h soundmod.h soundosx.h
soundsdl.lo: soundsdl.cc ../../bochs.h ../../config.h ../../osdep.h \
 ../../gui/paramtree.h ../../logio.h ../../instrument/stubs/instrument.h \
 ../../misc/bswap.h ../../plugin.h ../../extplugin.h ../../pc_system.h \
 soundlow.h ../../bxthread.h soundmod.h soundsdl.h
soundwin.lo: soundwin.cc ../../bochs.h ../../config.h ../../osdep.h \
 ../../gui/paramtree.h ../../logio.h ../../instrument/stubs/instrument.h \
 ../../misc/bswap.h ../../plugin.h ../../extplugin.h ../../pc_system.h \
 soundlow.h ../../bxthread.h soundmod.h soundwin.h
